package cc.greencat.gcmall.member.controller;

import cc.greencat.gcmall.common.utils.PageUtils;
import cc.greencat.gcmall.common.utils.R;
import cc.greencat.gcmall.member.entity.MemberInfoEntity;
import cc.greencat.gcmall.member.feign.PromotionFeignService;
import cc.greencat.gcmall.member.service.MemberInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 会员
 *
 * @author greencat.cc
 * @email greencatcc@163.com
 * @date 2021-01-11 21:41:47
 */
@RestController
@RequestMapping("member/memberinfo")
public class MemberInfoController {
    @Autowired
    private MemberInfoService memberInfoService;

    @Autowired
    private PromotionFeignService promotionFeignService;

    @RequestMapping("promotion/list1")
    public R list() {
        R r = promotionFeignService.list1();
        r.put("member", "member").put("coupons", r.get("coupons"));
        return r;
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("member:memberinfo:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = memberInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("member:memberinfo:info")
    public R info(@PathVariable("id") Long id){
		MemberInfoEntity memberInfo = memberInfoService.getById(id);

        return R.ok().put("memberInfo", memberInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("member:memberinfo:save")
    public R save(@RequestBody MemberInfoEntity memberInfo){
		memberInfoService.save(memberInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("member:memberinfo:update")
    public R update(@RequestBody MemberInfoEntity memberInfo){
		memberInfoService.updateById(memberInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("member:memberinfo:delete")
    public R delete(@RequestBody Long[] ids){
		memberInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
